﻿$(document).ready(function() {
	$("#lovecardivdialog").dialog({
		autoOpen : false,
		resizable:false,
		title:"添加爱车信息",
		position:[500,100]
	});
	$(document).ready(function () {
	    $('img#imagetest').imgAreaSelect({
	        handles: true,
	        aspectRatio: '1:1',
	        maxWidth: 200,
	        x1:50, y1:50, x2: 210, y2:210,
	        selectionOpacity: 0.2
	    });
	});
});
function saveSelected(){
	var pic=$('#imagetest').attr('src');
	var x=$('body .imgareaselect-outer:eq(0)').css("width").replace("px","");
	var y=$('body .imgareaselect-outer:eq(1)').css("height").replace("px","");
	var w=$('.imgareaselect-selection').css('width').replace("px","");
	var h=$('.imgareaselect-selection').css('height').replace("px","");
	$.getJSON("saveSelectedPicture.action",{x:x,y:y,w:w,h:h,pic:pic},function(data){
		//alert("头像修改成功");
		$.weeboxs.open('头像修改成功!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		$("#faceimg").attr("src",data.filepath);
		$("#lface img:eq(0)").attr("src",data.filepath);
	});
}

function baseMsg() {
	$("#baseMessage").show();
	$("#baseMessage").siblings().hide();
	$("div[class='imgareaselect-outer']").hide();
	$("div[class='imgareaselect-selection']").parent().hide();
	$("#1").css("background-color","#F1FACD");
	$("#1").siblings().css("background-color","#F8F8F8");
}
function changePsw() {
	clearPassword();
	$("#changePsw").show();
	$("#changePsw").siblings().hide();
	$("div[class='imgareaselect-outer']").hide();
	$("div[class='imgareaselect-selection']").parent().hide();
	$("#2").css("background-color","#F1FADD");
	$("#2").siblings().css("background-color","#F8F8F8");
}
function accRel() {
	$("#accRel").show();
	$("#accRel").siblings().hide();
	$("div[class='imgareaselect-outer']").hide();
	$("div[class='imgareaselect-selection']").parent().hide();
	var d = document.getElementById("accRel");
	d.innerHTML = "";
	$.getJSON("getUserRelatedThirdPartry.action",
		function(data) {
			if (data.QQ == 1) {
				d.innerHTML += "<div style='float:left'><font>已关联QQ帐号</font></div><div style='float:right'><input type='button' value='解除关联' /></div>";
			} else {
				d.innerHTML += "<div style='float:left'><font>还未关联QQ帐号</font></div><div style='float:right'><input type='button' value='关联QQ' /></div>";
			}
		});
	$("#3").css("background-color","#F1FADD");
	$("#3").siblings().css("background-color","#F8F8F8");
}
function accFace(){
	$("#lface").show();
	$("#lface").siblings().hide();
	$("#6").css("background-color","#F1FADD");
	$("#6").siblings().css("background-color","#F8F8F8");
}
function accSafe() {
	//alert("暂时不开放");
	$.weeboxs.open('暂时不开放!', {
		title:'提示',
		timeout:5,
		showCancel:false,
		okBtnName: '确定',
	});
//	$("#baseMessage").hide();
//	$("#changePsw").hide();
//	$("#accRel").hide();
//	$("#accSafe").show();
//	$("#lcar").hide();
//	document.getElementById("1").style.backgroundColor = "#F8F8F8";
//	document.getElementById("2").style.backgroundColor = "#F8F8F8";
//	document.getElementById("3").style.backgroundColor = "#F8F8F8";
//	document.getElementById("4").style.backgroundColor = "#F1FAFD";
//	document.getElementById("5").style.backgroundColor = "#F8F8F8";
}
function loveCarMsg() {
	$("#lcar").show();
	$("#lcar").siblings().hide();
	$("div[class='imgareaselect-outer']").hide();
	$("div[class='imgareaselect-selection']").parent().hide();
	var d = document.getElementById("lcar");
	d.innerHTML = "";
	$.getJSON("getUserLoveCarMsg.action",{
		d:new Date().getTime()
	},function(data) {
		if (data.llist == '') {
			d.innerHTML += "您还没设置您的爱车信息<br />";
		} else {
			var ii = 1;
			$.each(data.llist,function(i, v) {
				d.innerHTML += "<img src='"+ v.usersCarPic+ "' width='230px;'>";
				d.innerHTML += "<div id='lovecar"+ ii+ "'><input type='hidden' id='hiddencarid"+ ii
					+ "' value='"+ v.carId+ "'/>爱车品牌：<input type='text' value='"+ v.usersCarBrind
					+ "' class='logintxt' disabled='disabled' id='carbrand"+ ii+ "'/><br/></div>";
				if(v.usersCarName!=null&&v.usersCarName!=''&&v.usersCarName!='null'){
					$("#lovecar"+ii).append("爱车姓名：<input type='text' value='"+v.usersCarName
						+"' class='logintxt' disabled='disabled' id='carname"+ ii+ "'/><br/>");
				}else{
					$("#lovecar"+ii).append("<pp style='display:none'>爱车姓名：</font><input type='text' class='logintxt' id='carname"+ ii+ "'/><br/></pp>");
				}
				if(v.usersCarAge!=null&&v.usersCarAge!=''&&v.usersCarAge!='null'){
					$("#lovecar"+ii).append("爱车年龄：<input type='text' value='"+ v.usersCarAge
						+ "' class='logintxt' disabled='disabled' id='carage"+ ii+ "'/><br/>");
				}else{
					$("#lovecar"+ii).append("<pp style='display:none'>爱车年龄：</font><input type='text' class='logintxt' id='carage"+ ii+ "'/><br/></pp>");
				}
				if(v.usersCarPrice!=null&&v.usersCarPrice!=''&&v.usersCarPrice!='null'){
					$("#lovecar"+ii).append("爱车身价：<input type='text' value='"+ v.usersCarPrice+ "' " +
						"class='logintxt' disabled='disabled' id='carprice"+ ii+ "'/><br/>");
				}else{
					$("#lovecar"+ii).append("<pp style='display:none'>爱车身价：</font><input type='text' class='logintxt' id='carprice"+ ii+ "'/><br/></pp>");
				}
				if(v.userCarLicenseNumber!=null&&v.userCarLicenseNumber!=''&&v.userCarLicenseNumber!='null'){
					$("#lovecar"+ii).append("爱车牌照：<input type='text' value='"+ v.userCarLicenseNumber+
						"' class='logintxt' disabled='disabled' id='carnumber"+ ii+ "'/><br/>");
				}else{
					$("#lovecar"+ii).append("<pp style='display:none'>爱车牌照：</font><input type='text' class='logintxt' id='carnumber"+ ii+ "'/><br/></pp>");
				}
				if(v.userCarconfigure!=null&&v.userCarconfigure!=''&&v.userCarconfigure!='null'){
					$("#lovecar"+ii).append("爱车配置：<input type='text' value='"+ v.userCarconfigure
						+ "' class='logintxt' disabled='disabled' id='carconfiguration"+ ii + "'/><br/>");
				}else{
					$("#lovecar"+ii).append("<pp style='display:none'>爱车配置：<input type='text' class='logintxt' id='carconfiguration"+ ii+ "'/><br/></pp>");
				}
				d.innerHTML += "<input id='deleteLoveCarMsg"+ ii+ "' type='button' class='buttoncss' style='width:80px;' value='删除爱车' onclick='deleteCar("+ ii + ")'/>";
				d.innerHTML += "<input id='changeLoveCarMsg"+ ii+ "' type='button' class='buttoncss' style='margin-left:10px;' value='修改爱车资料' onclick='editcar("+ ii + ")'/><hr/>";
				ii++;
			});
		}
		d.innerHTML += "<input type='button' class='buttoncss' style='width:80px;' value='添加爱车' onclick='insertLoveCar()' style='float:left'/>";
	});
	$("#5").css("background-color","#F1FADD");
	$("#5").siblings().css("background-color","#F8F8F8");
}
var c1 = true;
function checkUser() {
	var user = document.getElementById("username").value;
	_user = document.getElementById("hiddenusername");
	if (user == "" || user == null) {
		//alert("用户名不能为空");
		$.weeboxs.open('用户名不能为空!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		c1 = false;
	} else if (!/^(\w){2,15}$/.test(user)) {
		//alert("用户名在2-15位之间");
		$.weeboxs.open('用户名在2-15位之间!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		c1 = false;
	} else if (user != _user) {
		c1 = true;
		$.post("yanuser.action", {
			username : user
		}, function(data) {
			if (data.str == "false") {
				//alert("此用户名已被注册");
				$.weeboxs.open('此用户名已被注册!', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
				c1 = false;
			}
		}, "json");
	}
}
function checkSubmit() {
	if (c1) {
		document.getElementById("form1").submit();
		//alert("信息修改成功");
		$.weeboxs.open('信息修改成功!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	} else {
		//alert("填写信息有错或者不完整");
		$.weeboxs.open('填写信息有错或者不完整!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}
function checkMobile() {
	var tele = document.getElementById("telephone").value;
	if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tele))) {
		$("#telephone").val("");
	}
}
function checkPhone() {
	var tele1 = document.getElementById("specialplane1").value;
	var tele2 = document.getElementById("specialplane2").value;
	if (!(/^\d{2,4}-\d{8}$/.test(tele1 + "-" + tele2))) {
		document.getElementById("specialplaneMsg").innerHTML = "×";
	}
}
var check1, check2, check3;
function checkOldPass() {
	var oldp = $("#oldpassword").val();
	if (oldp == null || oldp == "") {
		//alert("原密码不能为空");
		$.weeboxs.open('原密码不能为空!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		check1 = false;
	} else {
		check1 = true;
	}
}
function checkPass1() {
	var p1 = $("#p1").val();
	if (p1 == null || p1 == "") {
		//alert("新密码不能为空");
		$.weeboxs.open('新密码不能为空!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		check2 = false;
	} else {
		check2 = true;
	}
}
function checkPass2() {
	var p2 = $("#p2").val();
	if (p2 == null || p2 == "" || p2 != $("#p1").val()) {
		//alert("密码输入不一致");
		$.weeboxs.open('密码输入不一致!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		check3 = false;
	} else {
		check3 = true;
	}
}
function clearPassword() {
	$("#oldpassword").val("");
	$("#p1").val("");
	$("#p2").val("");
}
function changePassword() {
	if (check1 == true && check2 == true && check3 == true) {
		$.getJSON("changPasswordAction.action", {
			oldpassword : $("#oldpassword").val(),
			password : $("#p2").val()
		}, function(data) {
			if (data.result == "1") {
				//alert("原密码输入错误");
				$.weeboxs.open('原密码输入错误!', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
			} else if (data.result == "2") {
				//alert("密码修改成功");
				$.weeboxs.open('密码修改成功!', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
			}
		});
	} else {
		//alert("请填写完整");
		$.weeboxs.open('请填写完整!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function insertLoveCar() {
	$("#lovecardivdialog input").val("");
	$("#insertCarMsg").val("确定爱车资料");
	$("#lovecardivdialog").dialog("open");
}

function inserCar() {
	if($.trim($("input[name='lbrand']").val())!=''){
		if($.trim($("input[name='upload']").val())==''){
//			alert("爱车图片不能为空");
			$.weeboxs.open('爱车图片不能为空!', {
				title:'提示',
				timeout:5,
				showCancel:false,
				okBtnName: '确定',
			});
		}else{
			document.getElementById("fileform").submit();
			$("#lovecardivdialog").dialog("close");
			setTimeout(function(){
				loveCarMsg();
			},1000);
		}
	}else{
//		alert("爱车品牌不能为空");
		$.weeboxs.open('爱车品牌不能为空!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}
function editcar(a) {
	$("#lovecar" + a + " input").attr("disabled", false);// 移除此id下的lovecar这个div下的所有input的disabled属性
	$("#lovecar" + a + " pp").css("display", "block");
	$("#changeLoveCarMsg" + a).val("确认修改");
	$("#changeLoveCarMsg" + a).css("width","80px");
	$("#changeLoveCarMsg" + a).attr("onclick", "editCarActionClick(" + a + ")");
}

function editCarActionClick(a) {
	var brand = $("#carbrand" + a).val();
	var name = $("#carname" + a).val();
	var age = $("#carage" + a).val();
	var price = $("#carprice" + a).val();
	var number = $("#carnumber" + a).val();
	var configuration = $("#carconfiguration" + a).val();
	var id = $("#hiddencarid" + a).val();
	$.getJSON("updateLoveCarMsg.action", {
		brand : brand,
		name : name,
		age : age,
		price : price,
		number : number,
		configuration : configuration,
		id : id
	});
	$("#lovecar" + a + " input").attr("disabled", true);
	for(var ff=0;ff<5;ff++){
		if($("#lovecar" + a + " pp:eq("+ff+") input").val()==''){
			$("#lovecar" + a + " pp:eq("+ff+")").css("display","none");
		}
	}
	$("#changeLoveCarMsg" + a).val("修改爱车信息");
	$("#changeLoveCarMsg" + a).css("width","112px");
	$("#changeLoveCarMsg" + a).attr("onclick", "editcar(" + a + ")");
}

function deleteCar(a) {
	var p = confirm("确定删除吗");
	if (p) {
		var id = $("#hiddencarid" + a).val();
		$.getJSON("deleteLoveCarMsg.action", {
			id : id
		},function(){
			loveCarMsg();
		});
	}
}

function editemail(){
	$("#hiddenemailinput").slideDown("slow");
	$("#emailchangexx").val("确定");
	$("#emailchangexx").attr("onclick","quedingChangeemail()");
}

function quedingChangeemail(){
	var e=$.trim($("#inputEmail").val());
	if(e!=''&&/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e)){
		$("#hiddenemailinput").slideUp("slow");
		$("#emailchangexx").val("验证邮箱");
		$("#emailchangexx").attr("onclick","checkEmailAtCustomerEdit()");//需要实现这个function
		$.getJSON("changeSafeEmail.action",{
			email:e
		},function(data){
			$("#showsafeemail").html("未验证邮箱："+e);
		});
	}else{
		//alert("请输入正确Email地址");
		$.weeboxs.open('请输入正确的Email地址!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function faceUploadBack(a){
	$("#imagetest").attr("src",a);
	$("#imagetest").css("display","block");
}
